{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3c418603-4fd2-4460-aa74-36a4e7ad862c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from numba import jit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "44f84dda-b998-451a-b7a2-fb31bba10c5f",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "499999500000\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "\n",
    "@jit(nopython=True)  # 使用 nopython 模式以获得最佳性能\n",
    "def sum_array(arr):\n",
    "    total = 0\n",
    "    for i in range(arr.shape[0]):\n",
    "        total += arr[i]\n",
    "    return total\n",
    "\n",
    "\n",
    "arr = np.arange(1000000)\n",
    "result = sum_array(arr)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cc349ec2-65f5-4e03-b21b-2ebbedfb15ba",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (myenv)",
   "language": "python",
   "name": "myenv"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
